home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-06-25 | 1.9 KB | 98 lines | [TEXT/CWIE] |
- #include <ImageCompression.h>
- #include <QDOffscreen.h>
-
- #include "ScreenGrabber.h"
-
-
- #pragma mark Private Functions
- #pragma mark -
-
- static Boolean HasQuickTime()
- {
- Boolean has_qt = false;
- SInt32 response;
-
- if ( ( noErr == Gestalt(gestaltQuickTimeVersion, &response) ) &&
- ( response != 0 ) )
- {
- has_qt = true;
- }
-
- return has_qt;
- }
-
- static OSErr GetScreenGWorld(GWorldPtr &gworld, SInt16 screen_depth = 16)
- {
- OSErr result = noErr;
-
- result = NewGWorld(&gworld, screen_depth, &qd.screenBits.bounds, nil, nil, useTempMem);
-
- if ( result == noErr )
- {
- CopyBits(&qd.screenBits, &((GrafPtr)gworld)->portBits, &qd.screenBits.bounds, &qd.screenBits.bounds,
- srcCopy, nil);
- }
-
- return result;
- }
-
- #pragma mark -
- #pragma mark External Functions
- #pragma mark -
-
- OSErr GetScreenJPEG(Handle &h, SInt16 screen_depth)
- {
- OSErr result = noErr;
- GWorldPtr gworld = nil;
- SInt32 max_compress_size;
- ImageDescriptionHandle image_desc = nil;
-
- h = nil;
-
- if ( ! HasQuickTime() )
- return paramErr;
-
- result = GetScreenGWorld(gworld, screen_depth);
-
- if ( result == noErr )
- result = GetMaxCompressionSize(GetGWorldPixMap(gworld), &qd.screenBits.bounds,
- screen_depth, codecNormalQuality, 'jpeg',
- bestSpeedCodec, &max_compress_size);
-
- if ( result == noErr )
- {
- h = TempNewHandle(max_compress_size, &result);
-
- if ( result == noErr )
- result = MemError();
- }
-
- if ( result == noErr )
- {
- image_desc = (ImageDescriptionHandle)TempNewHandle(0, &result);
-
- if ( result == noErr )
- result = MemError();
- }
-
- if ( result == noErr )
- HLockHi(h);
-
- if ( result == noErr )
- result = CompressImage(GetGWorldPixMap(gworld), &qd.screenBits.bounds, codecNormalQuality,
- 'jpeg', image_desc, *h);
-
- if ( result == noErr )
- {
- HUnlock(h);
- SetHandleSize(h, (**image_desc).dataSize);
- }
-
- if ( gworld != nil )
- DisposeGWorld(gworld);
-
- if ( image_desc != nil )
- DisposeHandle((Handle)image_desc);
-
- return noErr;
- }